<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<script src="${contextPath}/resources/common/js/jquery.validate.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="screen" href="${contextPath}/resources/common/css/errorform.css" />
<script src="<ls:templateResource item='/resources/plugins/My97DatePicker/WdatePicker.js'/>" type="text/javascript"></script>
<link rel="stylesheet" href="<ls:templateResource item='/resources/plugins/kindeditor/themes/default/default.css'/>"/>
<link rel="stylesheet" href="<ls:templateResource item='/resources/plugins/kindeditor/plugins/code/prettify.css'/>"/>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/kindeditor-min.js'/>"></script>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/lang/zh_CN.js'/>"></script>
<script charset="utf-8" src="<ls:templateResource item='/resources/plugins/kindeditor/plugins/code/prettify.js'/>"></script>

<link href="<ls:templateResource item='/resources/plugins/select2-4.0/select2.css'/>" rel="stylesheet"/>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/select2.full.min.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/i18n/zh-CN.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/select2-4.0/makeSelect2.js'/>" type="text/javascript"></script>
<table class="${tableclass}" style="width: 100%">
	   <tr><th><strong class="am-text-primary am-text-lg">目标管理</strong> /
	    		<c:choose>
	                <c:when test="${not empty project}">修改目标</c:when>
	                	<c:otherwise>创建目标</c:otherwise>
	                </c:choose>
	                - ${project.name}
	    	</th></tr>
</table>

 <div style="margin-left: 0.5rem">
    <div class="seller_list_title">
        <ul class="seller_title_ul am-tabs-nav am-nav am-nav-tabs">
            <li><i></i><a href="<ls:url address="/admin/project/load/${project.id}"/>">项目信息</a></li>
            <li><i></i><a href="<ls:url address="/admin/projectPlan/query/${project.id}"/>">里程碑</a></li>
            <li class="am-active"><i></i><a href="<ls:url address="/admin/task/query/${project.id}"/>">目标</a></li>
            <li><i></i><a href="<ls:url address="/admin/projectModule/query/${project.id}"/>">模块</a></li>
            <li><i></i><a href="<ls:url address="/admin/projectMember/query/${project.id}"/>">团队</a></li>
            <li><i></i><a href="<ls:url address="/admin/projectReport/query/${project.id}"/>">报表</a></li>
        </ul>
    </div>
</div>  

<form action="<ls:url address='/admin/task/save'/>" method="post" id="form1">
	    <input id="id" name="id" value="${task.id}" type="hidden" />
	    <input id="nextStep" name="nextStep" type="hidden" />
	    <input id="projectId" name="projectId" value="${project.id}" type="hidden" />
		<table border="0" align="center" class="${tableclass}" id="col1">
			<tr>
				<td class="center_letter" style="min-width: 150px;">
					基本信息
				</td>
				<td>

					<c:if test="${not empty project.plans}">
						里程碑: <font color="ff0000">*</font>
						<select id="planId" name="planId">
							<option value=""><font color="red">-- 里程碑 --</font></option>
							<c:forEach items="${project.plans}" var = "plan">
								<option value="${plan.id}" <c:if test="${plan.id eq planId}">selected="selected"</c:if> >${plan.title}</option>
							</c:forEach>
						</select>
					</c:if>

					<c:if test="${not empty project.modules}">
					   所属模块: <font color="ff0000">*</font>
	 					<select id="moduleId" name="moduleId">
	 					   <option value=""><font color="red">-- 模块 --</font></option>
				      		<c:forEach items="${project.modules}" var = "module">
						        <option value="${module.id}" <c:if test="${module.id eq task.moduleId}">selected="selected"</c:if> >${module.name}</option>
						  	</c:forEach>
	 					</select>
					</c:if>


					目标类型:
				 <select id="type" name="type">
					<ls:optionGroup type="select" required="false" cache="true"
	                beanName="TASK_TYPE" selectedValue="${task.type}"/>
	             </select> 
	              &nbsp; 优先级  
				 <select id="priority" name="priority">
					<ls:optionGroup type="select" required="false" cache="true"
	                beanName="PRIORITY_LEVEL" selectedValue="${task.priority}"/>
	             </select> 
	             
	              &nbsp; 预计剩余
	              <input type="text" name="leftHours" id="leftHours" value="${task.leftHours}" size="5"/> 小时
	              <c:if test="${not empty task.totalConsumed}">, 已消耗时间：${task.totalConsumed}</c:if>
				</td>
			</tr>
			<tr>
				<td class="center_letter" width="230px;">
					目标名称: <font color="ff0000">*</font>
				</td>
				<td><input type="text" name="name" id="name" value="${task.name}" maxlength="150" size="100"/>
				<select id="color" name="color">
					<ls:optionGroup type="select" required="false" cache="true" defaultDisp="标题颜色"
	                beanName="TASK_COLOR" selectedValue="${task.color}"/>
	             </select> 
				</td>
			</tr>
			<tr>
				<td class="center_letter">
				日程规划
				</td>
				<td>
				     预计开始:
					<input readonly="readonly"  name="eststarted" id="eststarted" class="Wdate" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',onpicked:function(){deadline.focus();},maxDate:'#F{$dp.$D(\'deadline\')}'})" value='<fmt:formatDate value="${task.eststarted}" pattern="yyyy-MM-dd"/>' />
					
				   截止日期:
					<input readonly="readonly" name="deadline" id="deadline" class="Wdate" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startTime\')}'})" value='<fmt:formatDate value="${task.deadline}" pattern="yyyy-MM-dd"/>' />
				</td>
			</tr>
			<tr>
				<td class="center_letter">
						指派给: <font color="ff0000">*</font>
				</td>
				<td>
				   <select name="assignedto" id="assignedto" style="width: 200px">
				   <c:if test="${not empty task.assignedto}">
				   	  <option value="${task.assignedto}">${task.assignedtoRealName}</option>
				   	</c:if>
				   </select>
				   
				   发邮件给：
				  <select name="mailto" id="mailto" style="width: 400px">
				   </select>
				</td>
			</tr>
			<tr>
				<td class="center_letter">
						描述: 
				</td>
				<td>
				<c:choose>
					<c:when test="${empty task.memo}">
					   <textarea name="memo" id="memo" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;">
					   </textarea>
					</c:when>
					<c:otherwise>
					   <textarea name="memo" id="memo" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;">${task.memo}</textarea>
					</c:otherwise>
				</c:choose>
				   
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<div align="center">
						<input type="submit" value="提交" id="submitBtn"/>
						<input type="submit" value="下一个目标" id="nextSubmitBtn"/>
						<input type="reset" value="重置" />
						<input type="button" value="返回" onclick="window.location.href='${contextPath}/admin/task/query/${project.id}'" />
					</div>
				</td>
			</tr>
		</table>
</form>

<div style="margin-left: 250px;">
		      		<c:forEach items="${requestScope.list}" var = "event">
				          <div class="group-item">
				         		 <span id="index-index" class="priv">${event.title} 
				         		 <c:if test="${not empty event.relateData}">
				         		     <span data="${event.relateData}" class="relateData">+</span>
				         		 </c:if>
				         		  </span>
				          </div>
				  	</c:forEach>
</div>
<br/>

  <script language="javascript">
	 $.validator.setDefaults({
   });

    $(document).ready(function() {
    	$("#submitBtn").click(function(){
    		 $(this).attr("disabled",true);
			$("#nextStep").val("");
    		 $("#form1").submit();
    		  setTimeout("$('#submitBtn').removeAttr('disabled')",2000); //设置2秒后提交按钮 显示
    		});

		$("#nextSubmitBtn").click(function(){
			$(this).attr("disabled",true);
			$("#nextStep").val("next");
			$("#form1").submit();
			setTimeout("$('#submitBtn').removeAttr('disabled')",2000); //设置2秒后提交按钮 显示
		});



    jQuery("#form1").validate({
            rules: {
            name: {
                required: true,
                minlength: 2
            },
            aliasName: {
                required: true,
                minlength: 2
            },
            assignedto: "required",
            moduleId: "required",
			planId: "required",
			leftHours: {
                number: true
			}

        },
        messages: {
        	name: {
                required: "请输入名称",
                minlength: "名称最少输入长度为2个字符"
            },
            aliasName: {
                required: "请输入目标别名",
                minlength: "名称最少输入长度为2个字符"
            },
            assignedto: {
                required: "必填"
            },
			planId: {
				required: "必填"
			},
            moduleId: {
                required: "必填"
            },
            leftHours: {
        	    number: "必须要数字"
			}
        }
    });
 
		//斑马条纹
     	 $("#col1 tr:nth-child(even)").addClass("even");
         
         KindEditor.options.filterMode = false;
         KindEditor.create('textarea[name="memo"]', {
             cssPath: '${contextPath}/resources/plugins/kindeditor/plugins/code/prettify.css',
             uploadJson: '${contextPath}/editor/uploadJson/upload;jsessionid=${cookie.JSESSIONID.value}',
             fileManagerJson: '${contextPath}/editor/uploadJson/fileManager',
             allowFileManager: true,
			 afterBlur: function () {
				 this.sync();
			 },
             width: '100%',
             height: '200px',
             items : [
    				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
    				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
    				'insertunorderedlist', '|', 'emoticons', 'link']
         });
         
         
         
         prettyPrint();
         
        makeSelect2(contextPath + "/admin/adminUser/userListInTeam/${project.id}","#assignedto","目标执行人","value","key");
         
        makeMultiSelect2(contextPath + "/admin/adminUser/userListInTeam/${project.id}","#mailto","邮件接收人","value","key",true);
        
    	$(".relateData").hover(function(){
    		var data=$(this).attr("data");
    		layer.tips(data, $(this), {
    			  tips: [1, '#3595CC'],
    			  time: 40000
    			});
    	},function(){
    		layer.closeAll('tips'); //关闭所有的tips层 
    	});
});
    
    
    

</script>
